/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.platform.web.controller.agent;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.medusa.gruul.common.core.annotation.EscapeLogin;
import com.medusa.gruul.common.core.util.PageUtils;
import com.medusa.gruul.common.core.util.Result;
import com.medusa.gruul.platform.model.dto.agent.ApplyWithdrawDto;
import com.medusa.gruul.platform.model.vo.agent.WithdrawOrdersVo;
import com.medusa.gruul.platform.service.IAgentWithdrawOrderService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 提现工单表结构 前端控制器
 * </p>
 *
 * @author whh
 * @since 2020-10-04
 */
@RestController
@RequestMapping("/agent/console/withdraw")
@SaCheckLogin
public class AgentWithdrawOrderController {

    @Autowired
    private IAgentWithdrawOrderService agentWithdrawOrderService;

    @PostMapping("/apply")
    @EscapeLogin
    @ApiOperation(value = "申请提现", tags = "代理管理台相关")
    public Result applyWithdraw(@Validated @RequestBody ApplyWithdrawDto withdrawDto) {
        agentWithdrawOrderService.applyWithdraw(withdrawDto);
        return Result.ok();
    }

    @GetMapping
    @EscapeLogin
    @ApiOperation(value = "查询代理自己的提现工单", tags = "代理管理台相关")
    public Result<PageUtils<WithdrawOrdersVo>> withdrawOrders(@ApiParam(value = "指定页数", required = true) @RequestParam Integer page,
                                                              @ApiParam(value = "数据条数", required = true) @RequestParam Integer size,
                                                              @ApiParam(value = "工单状态 0:待审核 1:审核拒绝 2:已打款") @Valid @NotNull @Range(min = 0, max = 1) @RequestParam Integer status,
                                                              @ApiParam(value = "提现方式： 1-微信  2-支付宝  3-银行卡") @RequestParam(required = false) Integer type,
                                                              @ApiParam(value = "开始时间") @RequestParam(required = false) String startTime,
                                                              @ApiParam(value = "结束时间") @RequestParam(required = false) String endTime,
                                                              @ApiParam(value = "订单号") @RequestParam(required = false) String orderNumber
    ) {
        PageUtils<WithdrawOrdersVo> vos = agentWithdrawOrderService.withdrawOrders(page, size, status,type,startTime,endTime,orderNumber);
        return Result.ok(vos);
    }

}
